package com.nov.multidatasource.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.nov.multidatasource.config.RunBatchConfig;
import com.nov.multidatasource.dao.primary.V3FileInfoMapper;
import com.nov.multidatasource.dao.secondary.V6FileInfoMapper;
import com.nov.multidatasource.emuns.Cus7Enum;
import com.nov.multidatasource.entity.primary.V3FileInfo;
import com.nov.multidatasource.entity.secondary.V6FileExtraInfoEntity;
import com.nov.multidatasource.entity.secondary.V6FileInfo;
import com.nov.multidatasource.service.FileMoveService;
import com.nov.multidatasource.task.UploadOBSTask;
import com.nov.multidatasource.utils.SnowFlakeUtil;
import com.obs.services.ObsClient;
import com.tecrun.common.constant.ResultCode;
import com.tecrun.common.vo.RtnData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName DiskMoveToOBSServiceImpl
 * @Description TODO
 * @Author cxn
 * @CreateTime 2025/1/14 10:10
 * @Since 1.0.0
 */
@Service
@Slf4j
public class DiskMoveToOBSServiceImpl implements FileMoveService {
    @Resource
    private RunBatchConfig runBatchConfig;
    @Resource
    private V6FileInfoMapper v6FileInfoMapper;
    @Resource
    private V3FileInfoMapper v3FileInfoMapper;
    @Resource
    private ObsClient oBSClient;

//    @Override
//    public RtnData<String> dealNewFile() {
//        try {
//            List<V6FileInfo> v6FileInfoList = v6FileInfoMapper.selectV6NewIncreaseFile();
//            log.info("查询新增文件总数量:{}", v6FileInfoList.size());
//            if (CollectionUtil.isEmpty(v6FileInfoList)) {
//                log.info("无新增文件");
//                return RtnData.success("无新增文件");
//            }
//            ArrayList<Long> sucIds = new ArrayList<>();
//            ArrayList<Long> failIds = new ArrayList<>();
//            ArrayList<V6FileExtraInfoEntity> extList = new ArrayList<>();
//            for (V6FileInfo v6FileInfo : v6FileInfoList) {
//                if (StringUtils.isBlank(v6FileInfo.getFile_path())) {
//                    log.warn("文件filePath路径为空, fileId:{}", v6FileInfo.getFile_id());
//                    failIds.add(v6FileInfo.getId());
//                    continue;
//                }
//                V6FileExtraInfoEntity ext = new V6FileExtraInfoEntity();
//                ext.setId(SnowFlakeUtil.generateId().toString());
//                ext.setFileId(v6FileInfo.getFile_id());
//                ext.setStoreType("obs-store");
//                String filePath = v6FileInfo.getCus6();
//                if (filePath.startsWith("/")) {
//                    filePath = filePath.substring(1);
//                }
//                ext.setFileImageObject0(filePath);
//                extList.add(ext);
//                sucIds.add(v6FileInfo.getId());
////                RtnData<V6FileInfo> rtnData = new UploadOBSTask(v6FileInfo, oBSClient, runBatchConfig).call();
////                if (ResultCode.SUCCESS.getCode().equals(rtnData.getCode())) {
////                    sucIds.add(v6FileInfo.getId());
////                    extList.add(ext);
////                } else {
////                    log.warn("插入OBS失败, code:{}, msg:{}", rtnData.getCode(), rtnData.getMsg());
////                    failIds.add(v6FileInfo.getId());
////                }
//            }
//            dealNewDB(extList, sucIds, failIds);
//            return RtnData.success(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), "SUCCESS");
//        } catch (Exception e) {
//            log.info("任务执行失败", e);
//            return RtnData.success("ERROR");
//        }
//    }




}
